// var venueId=1;
var msg=new Vue({
	el:"#msg",
	data:{
		vid:0,
		venue:{},
		messages:[]
	},
	mounted(){
		axios.get("/venue/session").then(res=>{
			console.info("sessionVenue:")
			console.info(res.data.data);
			this.vid=res.data.data.vid;
			axios.get("/venue/find/"+this.vid).then(e=>{
				console.info(e.data.data);
				this.venue=e.data.data;
				// venue=e.data.data;
				console.info(this.venue)
				if (e.data.code===200){
					axios.get("/message/myMessages/"+this.venue.vid)
						.then(r=>{
							this.messages = r.data.data;
						})
						.catch(err=>{
							console.info(err)
						})
				}
			}).catch(er=>{
				console.info(er)
			});
		}).catch(err=>{
			console.info(err)
		});

	},
	methods:{
		getAllMessages:function(){
			axios.get("/message/myMessages/"+this.venue.vid)
				.then(r=>{
					this.messages = r.data.data;
				})
				.catch(err=>{
					console.info(err)
				})
		},
		isReaded:function (mid) {
			axios({
				method:"put",
				url:"/message/changeStatus/"+mid
			}).then(res=>{
				if (res.data.code===200){
					axios.get("/message/myMessages/"+this.venue.vid)
						.then(r=>{
							this.messages = r.data.data;

						})
						.catch(err=>{
							console.info(err)
						})
				}
			}).catch(err=>{

			});
		},
		acceptSigning:function (cid,mid) {
			axios({
				method:"post",
				url:"/signing/accept",
				data:{
					"cid":cid,
					"vid":this.vid
				}
			}).then(res=>{
				if (res.data.code===200){
					this.updateMessage(mid,"2");
					this.getAllMessages();
					alert("你已接受签约");
				}
				console.info(res.data.msg)
			}).catch(err=>{
				console.info(err)
			})
		},
		updateMessage:function (mid,rm) {
			if (rm === '3'){
				alert("你已拒绝签约");
			}
			axios({
				method:"put",
				url:"/message/updateRm",
				data:{
					"mid":mid,
					"rmstatus":rm
				}
			}).then(res=>{
				this.isReaded(mid);
				console.info(res.data.msg)
			}).catch(err=>{
				console.info(err)
			});

		}
	}
});